﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_QLSV.BusinessClassLibrary
{
    public class DangKyHocBUS
    {
        private static QLSVDataContext db = new QLSVDataContext();
        public static bool ThemDangKyHoc(DangKyHoc DangKyHoc)
        {
            try
            {
                db.DangKyHocs.InsertOnSubmit(DangKyHoc);
                db.SubmitChanges();
            }
            catch
            {
                //conflict primary key - the item is exist
                return false;
            }
            return true;
        }
        public static bool XoaDangKyHoc(int idDangKyHoc)
        {
            try
            {
                DangKyHoc old = db.DangKyHocs.Single(kh => kh.madkh == idDangKyHoc);
                db.DangKyHocs.DeleteOnSubmit(old);
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        public static bool CapNhatDangKyHocHoc(int id, DangKyHoc DangKyHoc)
        {
            try
            {
                DangKyHoc old = db.DangKyHocs.Single(kh => kh.madkh == id);
                old.mssv = DangKyHoc.mssv;
                old.mamonhoc = DangKyHoc.mamonhoc;
                old.hocky = DangKyHoc.hocky;
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        public static List<DangKyHoc> LayDanhSach()
        {
            try
            {
                return db.DangKyHocs.ToList();
            }
            catch(Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            return null;
        }
    }
}
